<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>

<div id="sub">
    <c:if test="${form.person.employee}">
    <h2>Position</h2>
    <fieldset title="Employee Details">
        <ul>
            <li><a href="#appoint">Approve leave</a></li>
            <li><a href="#appoint">Appoint to position</a></li>
            <li><a href="#appoint" onclick="dijit.byId('terminateEmployeeDialog').show();">Termination of employment</a></li>
        </ul>
    </fieldset>
    </c:if>

    <h2>Performance</h2>
    <fieldset title="Employee Details">
        <ul>
        <li><a href="#appoint">Compile goals</a></li>
        <li><a href="#appoint">Latest appraisal</a></li>
        <li><a href="#appoint">History report</a></li>
        </ul>
    </fieldset>
</div>

<div id="employeeForm">
<form:form id="employee" modelAttribute="form" action="save" method="post">
    <span class="errors">
	<form:errors path="*"/>
    </span>
    <h2>Employee details</h2>

    <fieldset title="Employee Details">

    <div class="field">
	    <div class="label">Employee No:</div>
	    <div class="input">
        <c:choose>
        <c:when test="${form.editable && form.person.employee}">
            <form:input id="employeeNo" path="person.employeeNo"/>
            <script type="text/javascript">
                Spring.addDecoration(new Spring.ElementDecoration({
                elementId : "employeeNo",
                widgetType : "dijit.form.ValidationTextBox",
                widgetAttrs : {
                    required : "true",
                    promptMessage : "Employee number is required",
                    invalidMessage : "Employee number is invalid."
                }
                }));
            </script>
        </c:when>
         <c:otherwise>
             <div class="output">${form.person.employeeNo}</div>
         </c:otherwise>
         </c:choose>
	    </div>
	</div>
    
	<div class="field">
	    <div class="label">First Name:</div>
	    <div class="input">
        <c:if test="${form.editable}">
            <form:input id="firstName" path="person.firstName"/>
            <script type="text/javascript">
                Spring.addDecoration(new Spring.ElementDecoration({
                elementId : "firstName",
                widgetType : "dijit.form.ValidationTextBox",
                widgetAttrs : {
                    required : "true",
                    promptMessage : "First name is required",
                    invalidMessage : "First name is required."
                }
                }));
            </script>
        </c:if>
        <c:if test="${!form.editable}">
            <div class="output">${form.person.firstName}</div>
        </c:if>
	    </div>
	</div>
	<div class="field">
	    <div class="label">Last Name:</div>
	    <div class="input">
            <c:if test="${form.editable}">
            <form:input id="lastName" path="person.lastName"/>
            <script type="text/javascript">
                Spring.addDecoration(new Spring.ElementDecoration({
                elementId : "lastName",
                widgetType : "dijit.form.ValidationTextBox",
                widgetAttrs : {
                    required: "true",
                    promptMessage : "Last name is required",
                    invalidMessage : "Last name is required"
                }}));
            </script>
            </c:if>
            <c:if test="${!form.editable}">
            <div class="output">${form.person.lastName}</div>
            </c:if>
	    </div>
	</div>
    <div class="field">
	    <div class="label">Identity No:</div>
	    <div class="input">
            <c:if test="${form.editable}">
            <form:input id="identityNo" path="person.identityNo"/>
            <script type="text/javascript">
                Spring.addDecoration(new Spring.ElementDecoration({
                elementId : "identityNo",
                widgetType : "dijit.form.ValidationTextBox",
                widgetAttrs : {
                    required: "true",
                    promptMessage : "Identity no. is required",
                    invalidMessage : "Identity no. is required"
                }}));
            </script>
            </c:if>
            <c:if test="${!form.editable}">
            <div class="output">${form.person.identityNo}</div>
            </c:if>
	    </div>
	</div>

    <div class="field">
	    <div class="label">Gender:</div>
	    <div class="input">
            <c:if test="${form.editable}">
            <form:select id="gender" path="person.gender.id">
                <form:options items="${genders}" itemLabel="name" itemValue="id"/>
            </form:select>
            <script type="text/javascript">
                Spring.addDecoration(new Spring.ElementDecoration({
                elementId : "gender",
                widgetType : "dijit.form.FilteringSelect",
                widgetAttrs : {
                    required: "false"
                }}));
            </script>
            </c:if>
            <c:if test="${!form.editable}">
            <div class="output">${form.person.gender.name}</div>
            </c:if>
	    </div>
	</div>

    <div class="field">
	    <div class="label">Population group:</div>
	    <div class="input">
            <c:if test="${form.editable}">
            <form:select id="populationGroup" path="person.populationGroup.id">
                <form:options items="${populationGroups}" itemLabel="name" itemValue="id"  />
            </form:select>
            <script type="text/javascript">
                Spring.addDecoration(new Spring.ElementDecoration({
                elementId : "populationGroup",
                widgetType : "dijit.form.FilteringSelect",
                widgetAttrs : {
                    required: "false"
                }}));
            </script>
            </c:if>
            <c:if test="${!form.editable}">
            <div class="output">${form.person.populationGroup.name}</div>
            </c:if>
	    </div>
	</div>

    <div id="positionField" class="field">
	    <div class="label">Date of birth:</div>
	    <div class="input">
            <c:choose>
            <c:when test="${form.editable}">
            <form:input id="dateOfBirth" path="person.dateOfBirth"/>
            <script type="text/javascript">
                Spring.addDecoration(new Spring.ElementDecoration({
                elementId : "dateOfBirth",
                widgetType : "dijit.form.DateTextBox",
                widgetAttrs : {
                    required : "true",
                    value : dojo.date.locale.parse(dojo.byId("dateOfBirth").value, {selector : "date", datePattern : "yyyy-MM-dd"}),
                    constraints : {datePattern : "yyyy-MM-dd"},
                    promptMessage : "Required (eg. 2008-05-31)",
                    invalidMessage : "Format is yyyy-MM-dd (eg. 2008-05-31)"
                }
                }));
            </script>
            </c:when>
            <c:otherwise>
            <div class="output">${form.person.dateOfBirth}</div>
            </c:otherwise>
            </c:choose>
	    </div>
	</div>

    <c:if test="${not empty form.person.position}">
    <div class="field">
	    <div class="label">Position:</div>
	    <div class="input">
            <c:if test="${form.editable}">
            <div class="output">${form.person.position.name}</div>
            </c:if>
            <c:if test="${!form.editable}">
            <div class="output">${form.person.position.name}</div>
            </c:if>
	    </div>
	</div>
    </c:if>
    <c:if test="${empty form.person.position}">
        <div class="label">Position:</div>
	    <div class="input">
            <div class="output">Not appointed to a position</div>
        </div>
    </c:if>

    <c:if test="${not empty form.person.department}">
    <div class="field">
	    <div class="label">Department:</div>
	    <div class="input">
        <c:choose>
        <c:when test="${form.editable}">
            <div class="output">${form.person.department.name}</div>
        </c:when>
        <c:otherwise>
            <div class="output">${form.person.department.name}</div>
        </c:otherwise>
        </c:choose>
	    </div>
	</div>
    </c:if>

    <c:if test="${not empty form.person.position}">
    <div class="field">
	    <div class="label">Date joined:</div>
	    <div class="input">
            <c:choose>
            <c:when test="${form.editable}">
            <div class="output">${form.person.dateJoined}</div>
            </c:when>
            <c:otherwise>
            <div class="output">${form.person.dateJoined}</div>
            </c:otherwise>
            </c:choose>
	    </div>
	</div>
    </c:if>

    <c:if test="${not empty form.person.position}">
    <div class="field">
	    <div class="label">Date appointed:</div>
	    <div class="input">
            <c:choose>
            <c:when test="${form.editable}">
            <div class="output">${form.person.position.dateAppointed}</div>
            </c:when>
            <c:otherwise>
            <div class="output">${form.person.position.dateAppointed}</div>
            </c:otherwise>
            </c:choose>
	    </div>
	</div>
    </c:if>

    <c:if test="${not empty form.person.position && not empty form.person.position.dateDischarged}" >
    <div class="field">
	    <div class="label">Date discharged:</div>
	    <div class="input">
            <c:choose>
            <c:when test="${form.editable}">
            <div class="output">${form.person.position.dateDischarged}</div>
            </c:when>
            <c:otherwise>
            <div class="output">${form.person.position.dateDischarged}</div>
            </c:otherwise>
            </c:choose>
	    </div>
	</div>
    </c:if>

    <c:if test="${not empty form.person.dateTerminated}" >
    <div class="field">
	    <div class="label">Date terminated:</div>
	    <div class="input">
            <c:choose>
            <c:when test="${form.editable}">
            <div class="output">${form.person.dateTerminated}</div>
            </c:when>
            <c:otherwise>
            <div class="output">${form.person.dateTerminated}</div>
            </c:otherwise>
            </c:choose>
	    </div>
	</div>
    </c:if>
    
    <form:hidden id="id" path="person.id" />
	<form:hidden id="search" path="search.search" />
    <form:hidden id="pageSize" path="search.pageSize" />
    <form:hidden id="page" path="search.page" />

	<div class="buttonGroup">
        <c:if test="${form.editable}">
        <input type="submit" id="proceed" name="_eventId_proceed" value="Proceed" />&#160;
            <script type="text/javascript">
            Spring.addDecoration(new Spring.AjaxEventDecoration({
            elementId: "proceed",
            event: "onclick",
            formId: "employee",
            params: { fragments: "employeeForm" }
            }));
            Spring.addDecoration(new Spring.ValidateAllDecoration({
                elementId:'proceed',
                event:'onclick'}));
            </script>

        <input type="submit" name="_eventId_cancel" value="Cancel"/>&#160;
        </c:if>
	</div>
    </fieldset>
</form:form>
</div>